Current Location: Home> Function Categories> scandir

scandir

List files and directories in the specified path
Name:scandir
Category:Directory functions
Programming Language:php
One-line Description:Returns an array of files and directories in the specified directory.

Definition and usage

scandir() function returns an array of files and directories in the specified directory.

Example

List the files and directories in the images directory:

 <?php
$dir = "/images/" ;

// Sort in ascending order - default
$a = scandir ( $dir ) ;

// Sort in descending order
$b = scandir ( $dir , 1 ) ;

print_r ( $a ) ;
print_r ( $b ) ;
?>

result:

 Array
(
[0] => .
[1] => ..
[2] => cat.gif
[3] => dog.gif
[4] => horse.gif
[5] => myimages
)
Array
(
[0] => myimages
[1] => horse.gif
[2] => dog.gif
[3] => cat.gif
[4] => ..
[5] => .
)
Similar Functions
Popular Articles